package com.guigu.qingcheng.orderservice.controller;


import com.guigu.qingcheng.orderservice.entity.MyOrder;
import com.guigu.qingcheng.orderservice.mapper.TbReturnOrderMapper;
import com.guigu.qingcheng.orderservice.service.TbReturnOrderService;
import com.guigu.qingcheng.pojo.order.TbOrder;
import com.guigu.qingcheng.pojo.order.TbReturnOrder;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("returnorder")
public class TbReturnOrderController {
    @Autowired
    private TbReturnOrderService tbReturnOrderService;
    @Resource
    private TbReturnOrderMapper mapper;

    @GetMapping("findById")
    public R findById (Integer id) {
        TbReturnOrder tbReturnOrder = tbReturnOrderService.getById(id);
        if (tbReturnOrder  == null)
            return R.error();
        return R.ok().data("tbReturnOrder",tbReturnOrder);
    }


    //查询分页查询
    @PostMapping("findPagetk")
    public R findPagetk (@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestBody(required = false) Map<String,Object> searchMap ) {
        R pagetk = tbReturnOrderService.findPagetk(page, size, searchMap);
        return pagetk;
    }
    //查询分页查询
    @PostMapping("findPageth")
    public R findPageth (@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestBody(required = false) Map<String,Object> searchMap ) {
        return tbReturnOrderService.findPageth(page, size, searchMap);
    }


    //新增
    @PostMapping("add")
    public R add (@RequestBody TbReturnOrder tbReturnOrder) {
        boolean save = tbReturnOrderService.save(tbReturnOrder);
        if (save)
            return R.ok();
        return R.error();
    }

    //修改
    @PostMapping("update")
    public R updateOrder (@RequestBody TbReturnOrder tbReturnOrder) {
        return tbReturnOrderService.updateOrder(tbReturnOrder);
    }

    //修改
    @PostMapping("bhupdate")
    public R bhupdateOrder (@RequestBody TbReturnOrder tbReturnOrder) {
        return tbReturnOrderService.bhupdateOrder(tbReturnOrder);
    }

    //删除
    @GetMapping("delete")
    public R delete (String id) {
        boolean save = tbReturnOrderService.removeById(id);
        if (save)
            return R.ok();
        return R.error();
    }

    @GetMapping("deletes")
    public R deletes (String ids) {
        return tbReturnOrderService.deletes(ids);
    }

    //退款
    @PostMapping("addOrder")
    public R addOrder (@RequestBody TbOrder tbOrder, @RequestParam("radio")String radio,
                       @RequestParam("result")String result, @RequestParam("remarks")String remarks, @RequestParam("yy")String yy) {

        return tbReturnOrderService.addOrder(tbOrder,radio,result,remarks,yy);
    }

    @GetMapping("goodById")
    public R goodById (String id) {
        List<Map> list = mapper.listgoods(id);
        if (list.size()<0)
            return R.error();
        return R.ok().data("goods",list);
    }

    @PostMapping("updateOrder")
    public R updateOrderId (@RequestBody List<MyOrder> myOrders) {
        return tbReturnOrderService.updateOrderId(myOrders);
    }
}

